﻿using HandyControl.Controls;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using wms_wpf.Apiservice;
using wms_wpf.Dto;
using wms_wpf.Extend;
using wms_wpf.InPut;
using wms_wpf.Views;
using MessageBox = HandyControl.Controls.MessageBox;

namespace wms_wpf.ViewModels
{
    public class LogViewModel:BindableBase, INavigationAware
    {
        public LogView LogView { get; set; }
        private IViewService service { get; set; }
        public LogViewModel(LogView logView)
        {
            this.LogView = logView;
            service = new ViewService();        
            InPut_ViewService6 =new InPut_ViewService6();
            InPut_ViewService6.PageIndex = 1;
            InPut_ViewService6.PageSize = 20;
            GetList_View_LogCommand = new DelegateCommand(GetList_View_LogAsync);
            ExportMaterialbaseCommand = new DelegateCommand(ExportMaterialbase);
            ExportLogCommand = new DelegateCommand(ExportLog);
            GetList_View_LogAsync();
        }
        private List<View_LogDto> view_LogDtos;
        public List<View_LogDto> View_LogDtos
        {
            get { return view_LogDtos; }
            set { view_LogDtos = value; RaisePropertyChanged(); }
        }
        public DelegateCommand GetList_View_LogCommand { get; set; }
        public DelegateCommand ExportMaterialbaseCommand { get; set; }
        public DelegateCommand ExportLogCommand { get; set; }
        private InPut_ViewService6 inPut_ViewService6;
        public InPut_ViewService6 InPut_ViewService6
        {
            get { return inPut_ViewService6; }
            set { inPut_ViewService6 = value; RaisePropertyChanged(); }
        }

        private long count;
        public long Count
        {
            get { return count; }
            set { count = value; RaisePropertyChanged(); }
        }
        private long pagecount;
        public long PageCount
        {
            get { return pagecount; }
            set { pagecount = value; RaisePropertyChanged(); }
        }

        private string order;
        public string Order
        {
            get { return order; }
            set { order = value;RaisePropertyChanged(Order); }
        }


        //物料表导出
        public async void ExportMaterialbase()
        {
            InPut_ViewService inPut_ViewService = new InPut_ViewService();
            inPut_ViewService.PageSize = 50000;
            inPut_ViewService.PageIndex = 1;
            Tuple<List<View_MaterialsDto>, long?, long?> tuple = await service.GetList_View_Materials(inPut_ViewService); 
            if (tuple == null)
            {
                return;
            }
            ExportToExcel.ExportToExcelMethod(tuple.Item1);
        }
        public async void ExportLog()
        {
            InPut_ViewService6 inPut_ViewService = new InPut_ViewService6();
            inPut_ViewService.OrderNo=InPut_ViewService6.OrderNo;
            inPut_ViewService.PageSize = 50000;
            inPut_ViewService.PageIndex = 1;
            inPut_ViewService.Type = "取料";
            Tuple<List<View_LogDto>, long?, long?> tuple = await service.GetList_View_Logs(inPut_ViewService);
            if (tuple == null)
            {
                return;
            }
            ExportToExcel.ExportLogToExcelMethod(tuple.Item1);
        }

        public async void GetList_View_LogAsync()
        {      
            Tuple<List<View_LogDto>, long?, long?> tuple = await service.GetList_View_Logs(InPut_ViewService6);
            if (tuple == null)
            {
                return;
            }
            View_LogDtos = tuple.Item1;
            Count = (long)tuple.Item2;
            PageCount = (long)tuple.Item3;
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
           
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return false;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
            
        }
    }
}
